package com.jeecg.p3.system.poster.service;

import com.jeecg.p3.system.poster.dao.ExamQuestionBankDao;
import com.jeecg.p3.system.poster.entity.ExamQuestionBank;
import com.jeecg.p3.system.util.UuidUtils;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 *
 * @ClassName: ExamQuestionBankDao
 * @Description: TODO 题库数据处理层
 * @author: zhangxiao
 * @date: 2021年1月10日 下午7:29:38
 */
@Service
public class ExamQuestionBankService {
    @Resource
    private ExamQuestionBankDao dao;

    /**
     * 分页查询题库
     * @param pageQuery
     * @return
     */
    public PageList<ExamQuestionBank> queryPageList(PageQuery<ExamQuestionBank> pageQuery) {
        PageList<ExamQuestionBank> result = new PageList<ExamQuestionBank>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<ExamQuestionBank> wrapper = new PageQueryWrapper<ExamQuestionBank>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<ExamQuestionBank> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取题库数量
     * @param examQuestionBank
     * @return
     */
    public Integer count(ExamQuestionBank examQuestionBank) {
        PageQuery<ExamQuestionBank> pageQuery = new PageQuery<>();
        pageQuery.setQuery(examQuestionBank);
        return dao.count(pageQuery);
    }

    /**
     * 新增题库信息
     * @param examQuestionBank
     */
    public void doAdd(ExamQuestionBank examQuestionBank) {
        examQuestionBank.setId(UuidUtils.getId());
        dao.insert(examQuestionBank);
    }

    /**
     * 根据id查询题库信息
     * @param id
     * @return
     */
    public ExamQuestionBank findById(String id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取题库列表信息
     * @param examQuestionBank
     * @return
     */
    public List<ExamQuestionBank> findByParam(ExamQuestionBank examQuestionBank) {
        if(examQuestionBank == null) {
            examQuestionBank = new ExamQuestionBank();
        }
        return dao.findByParam(examQuestionBank);
    }

    /**
     * 编辑题库信息
     * @param examQuestionBank
     */
    public void doEdit(ExamQuestionBank examQuestionBank) {
        dao.update(examQuestionBank);
    }

    /**
     * 删除题库信息
     * @param examQuestionBank
     */
    public void doDelete(ExamQuestionBank examQuestionBank) {
        examQuestionBank.setStatus("0");
        dao.update(examQuestionBank);
    }
}
